#!/bin/sh
set -e

if [ -f "/usr/share/gr-rainbond-node/gaops.tgz" ];then
	mkdir -p /usr/share/gr-rainbond-node/gaops/
	tar xf /usr/share/gr-rainbond-node/gaops.tgz -C /usr/share/gr-rainbond-node/gaops/
fi

case "$1" in
	configure)
        if [ -n "$NODE_TYPE" ];then
			mkdir -p /etc/goodrain/envs/
			grep "MANAGE" /etc/goodrain/envs/ip.sh >/dev/null 2>&1
            if [ $? -eq 0 ];then
                echo "NODE_TYPE=compute" > /etc/goodrain/envs/rainbond-node.sh
            else
                echo "NODE_TYPE=" > /etc/goodrain/envs/rainbond-node.sh
            fi
        fi
		;;
	abort-*)
		# How'd we get here??
		exit 1
		;;
	*)
		;;
esac